{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 积分落户\n",
    "- 分析官方工具的积分落户数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'currentPageEndRecord': 10,\n",
       " 'currentPageNo': 1,\n",
       " 'currentPageSize': 10,\n",
       " 'currentPageStartRecord': 1,\n",
       " 'firstPage': True,\n",
       " 'hasNextPage': True,\n",
       " 'hasPreviousPage': False,\n",
       " 'lastPage': False,\n",
       " 'nextPageNo': 2,\n",
       " 'pageSize': 10,\n",
       " 'previousPageNo': 1,\n",
       " 'rows': [{'csrq': '1972-12',\n",
       "   'name': '杨效丰',\n",
       "   'pxid': 1,\n",
       "   'score': 122.59,\n",
       "   'unit': '北京利德华福电气技术有限公司'},\n",
       "  {'csrq': '1974-12',\n",
       "   'name': '纪丰伟',\n",
       "   'pxid': 2,\n",
       "   'score': 121.25,\n",
       "   'unit': '北京航天数据股份有限公司'},\n",
       "  {'csrq': '1974-05',\n",
       "   'name': '王永',\n",
       "   'pxid': 3,\n",
       "   'score': 118.96,\n",
       "   'unit': '品牌联盟(北京)咨询股份公司'},\n",
       "  {'csrq': '1975-07',\n",
       "   'name': '杨静',\n",
       "   'pxid': 4,\n",
       "   'score': 118.21,\n",
       "   'unit': '中科专利商标代理有限责任公司'},\n",
       "  {'csrq': '1974-11',\n",
       "   'name': '张凯江',\n",
       "   'pxid': 5,\n",
       "   'score': 117.79,\n",
       "   'unit': '北京阿里巴巴云计算技术有限公司'},\n",
       "  {'csrq': '1974-01',\n",
       "   'name': '罗恒',\n",
       "   'pxid': 6,\n",
       "   'score': 117.34,\n",
       "   'unit': '艾美仕市场调研咨询（上海）有限公司北京分公司'},\n",
       "  {'csrq': '1972-06',\n",
       "   'name': '刘春静',\n",
       "   'pxid': 7,\n",
       "   'score': 116.17,\n",
       "   'unit': '北京香侬发动机科技有限公司'},\n",
       "  {'csrq': '1974-03',\n",
       "   'name': '李玉俊',\n",
       "   'pxid': 8,\n",
       "   'score': 116.13,\n",
       "   'unit': '北京诺华制药有限公司'},\n",
       "  {'csrq': '1975-02',\n",
       "   'name': '穆立',\n",
       "   'pxid': 9,\n",
       "   'score': 115.95,\n",
       "   'unit': '中国光大银行股份有限公司'},\n",
       "  {'csrq': '1972-10',\n",
       "   'name': '李加昌',\n",
       "   'pxid': 10,\n",
       "   'score': 115.91,\n",
       "   'unit': '中国建筑第二工程局有限公司'}],\n",
       " 'total': 6019,\n",
       " 'totalPages': 602}"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import json\n",
    "import requests\n",
    "#https://mp.weixin.qq.com/s?__biz=MzIzNTQzMjU4NQ==&mid=2247489305&;idx=1&sn=63fc2887e7e4e255c0a525e8aa0f02b8&amp;chksm=e8e668ffdf91e1e9ef092f69678c220654e66da38f0569bfc6ab7a2041c24abbbf8d90590c49&mpshare=1&scene=23&srcid=1016HlLZZ9rqvVrQtF66I1d9%23rd\n",
    "url = 'http://www.bjrbj.gov.cn/integralpublic/settlePerson/settlePersonJson?sort=pxid&order=asc&;limit=100&amp;offset=0&amp;name=&amp;rows=6019&amp;page=1'\n",
    "res_dict = json.loads(requests.get(url).text)\n",
    "res_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "data = pd.DataFrame(res_dict['rows'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{115: 2, 116: 2, 117: 2, 118: 2, 121: 1, 122: 1}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d = data.groupby('score').size().to_dict()\n",
    "d1 = {}\n",
    "for k,v in d.items():\n",
    "    #print k,v\n",
    "    d1[int(k)] = d1.get(int(k), 0) + v\n",
    "d1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "s='421126198702042817'\n",
    "#前6位为行政区划分代码，第7位至14位为出生日期码，第15位至17位为顺序码，第18位为校验码，第15位代表性别，奇数为男，偶数为女\n",
    "#身份证信息查询：https://m.chazidian.com/sfz/421126198702042817/，http://m.9i0.com/（含性别）\n",
    "city_dict = {11:\"北京\",12:\"天津\",13:\"河北\",14:\"山西\",15:\"内蒙古\",21:\"辽宁\",22:\"吉林\",23:\"黑龙江 \",31:\"上海\",32:\"江苏\",33:\"浙江\",34:\"安徽\",35:\"福建\",36:\"江西\",37:\"山东\",41:\"河南\",42:\"湖北 \",43:\"湖南\",44:\"广东\",45:\"广西\",46:\"海南\",50:\"重庆\",51:\"四川\",52:\"贵州\",53:\"云南\",54:\"西藏 \",61:\"陕西\",62:\"甘肃\",63:\"青海\",64:\"宁夏\",65:\"新疆\",71:\"台湾\",81:\"香港\",82:\"澳门\",91:\"国外 \"};"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6 <class 'list'> <class 'str'> ['115', '116', '117', '118', '121', '122']\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "'dict_values' object does not support indexing",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-6-33d7882517e6>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      9\u001b[0m \u001b[1;31m# v = [int(np.abs(30*np.sin(i))) for i in k]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     10\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mk\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mk\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mk\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mk\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 11\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mv\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mv\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mv\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mv\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     12\u001b[0m \u001b[0mline\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0madd\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'number'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mk\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mv\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     13\u001b[0m \u001b[0mline\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrender\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'line.html'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: 'dict_values' object does not support indexing"
     ],
     "output_type": "error"
    }
   ],
   "source": [
    "import pyecharts as pe\n",
    "import numpy as np\n",
    "\n",
    "line = pe.Line('分数分布')\n",
    "k = d1.keys()\n",
    "k = [str(i) for i in d1.keys()]\n",
    "v = d1.values()\n",
    "# k = [i+5 for i in range(10)]\n",
    "# v = [int(np.abs(30*np.sin(i))) for i in k]\n",
    "print(len(k),type(k),type(k[0]),k)\n",
    "print(len(v),type(v),type(v[0]),v)\n",
    "line.add('number',k, v)\n",
    "line.render('line.html')\n",
    "line\n",
    "\n",
    "#d1.values()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!pwd"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
